﻿Imports System.Data.SqlClient

Public Class frmSlipsInsuranceArchive

    Sub FillSlipss()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim cmd As New SqlCommand("Select SlipNo,ClassOfBuiness,LineOfBuiness,Abbreviation,UserName,TransDate From Slips Order By SNo", cnn)
            Dim Reader As SqlDataReader
           
            Me.ListSlips.Items.Clear()

            cnn.Open()
            Reader = cmd.ExecuteReader
            While Reader.Read
                Dim Item As New ListViewItem
                Item.Text = Reader.Item("SlipNo")
                Item.SubItems.Add(Reader.Item("ClassOfBuiness"))
                Item.SubItems.Add(Reader.Item("LineOfBuiness"))
                Item.SubItems.Add(Reader.Item("Abbreviation"))
                Item.SubItems.Add(Reader.Item("UserName"))
                Item.SubItems.Add(CDate(Reader.Item("TransDate")).ToString("yyyy/MM/dd"))

                Me.ListSlips.Items.Add(Item)
            End While
            cnn.Close()

            'Count no. of results
            Me.lblResult.Text = "Results found: " & Me.ListSlips.Items.Count

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            Me.Cursor = Cursors.Default
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click
        FillSlipss()
    End Sub

    Private Sub ListSlips_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListSlips.SelectedIndexChanged
        If Me.ListSlips.SelectedItems.Count = 0 Then
            Me.CrystalReportViewer1.ReportSource = Nothing
        Else
            Try
                Me.Cursor = Cursors.WaitCursor

                Dim dap As New SqlDataAdapter("Select * From Slips Where SlipNo=@SlipNo", cnn)
                Dim das As New DataSet

                dap.SelectCommand.Parameters.AddWithValue("@SlipNo", Me.ListSlips.SelectedItems(0).Text)

                cnn.Open()
                dap.Fill(das, "Slips")
                cnn.Close()


                Select Case Me.ListSlips.SelectedItems(0).SubItems(3).Text
                    'Case "PII"
                    '    Dim rpt As New SlipPUL
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "FAP"
                    '    Dim rpt As New SlipFAP
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MON"
                    '    Dim rpt As New SlipMON
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MBI"
                    '    Dim rpt As New SlipMBD
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "PAR"
                    '    Dim rpt As New SlipPAR
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    '    'Case "F&L"
                    '    '    Dim rpt As New SlipPAR_FandL_FAP
                    '    '    rpt.SetDataSource(das)
                    '    '    Me.CrystalReportViewer1.ReportSource = rpt

                    '    'Case "FAP"
                    '    '    Dim rpt As New SlipPAR_FandL_FAP
                    '    '    rpt.SetDataSource(das)
                    '    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "CGL"
                    '    Dim rpt As New SlipCGL
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "FAP"
                    '    Dim rpt As New SlipFAP
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MAC"
                    '    Dim rpt As New SlipMAC
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "CPM"
                    '    Dim rpt As New SlipCPM
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "CAR"
                    '    Dim rpt As New SlipCAR
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MVF"
                    '    Dim rpt As New SlipMVF_MTPL
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MTPL"
                    '    Dim rpt As New SlipMVF_MTPL
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "MHW"
                    '    Dim rpt As New SlipMHW
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "AOL"
                    '    Dim rpt As New SlipAOL
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "ELI"
                    '    Dim rpt As New SlipELI
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "PES"
                    '    Dim rpt As New SlipPEI
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt


                    'Case "FGI"
                    '    Dim rpt As New SlipFG
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "WCA"
                    '    Dim rpt As New SlipWCA
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                    'Case "PLC"
                    '    Dim rpt As New SlipPLC_CCI
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt


                    'Case "CCI"
                    '    Dim rpt As New SlipPLC_CCI
                    '    rpt.SetDataSource(das)
                    '    Me.CrystalReportViewer1.ReportSource = rpt

                End Select

                Me.ListSlips.Focus()

                Me.Cursor = Cursors.Default
            Catch ex As Exception
                Me.Cursor = Cursors.Default
                If cnn.State = ConnectionState.Open Then
                    cnn.Close()
                End If
                MsgBox(ex.ToString)
            End Try
        End If
    End Sub

    Private Sub frmSlipsInsuranceArchive_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
    End Sub
End Class